home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / RTrace 1.0 / source / picture.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-16  |  4.8 KB  |  131 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Copyright (c) 1988, 1992 Antonio Costa, INESC-Norte.
  3.  * All rights reserved.
  4.  *
  5.  * This code received contributions from the following people:
  6.  *
  7.  *  Roman Kuchkuda      - basic ray tracer
  8.  *  Mark VandeWettering - MTV ray tracer
  9.  *  Augusto Sousa       - overall, shading model
  10.  *  Reid Judd        - improvements
  11.  *
  12.  * Redistribution and use in source and binary forms are permitted
  13.  * provided that the above copyright notice and this paragraph are
  14.  * duplicated in all such forms and that any documentation,
  15.  * advertising materials, and other materials related to such
  16.  * distribution and use acknowledge that the software was developed
  17.  * by Antonio Costa, at INESC-Norte. The name of the author and
  18.  * INESC-Norte may not be used to endorse or promote products derived
  19.  * from this software without specific prior written permission.
  20.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  21.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  22.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  23.  */
  24. #include "defs.h"
  25. #include "extern.h"
  26.  
  27. /**********************************************************************
  28.  *    RAY TRACING - Picture - Version 7.3.1                           *
  29.  *                                                                    *
  30.  *    MADE BY    : Antonio Costa, INESC-Norte, October 1988           *
  31.  *    ADAPTED BY : Antonio Costa, INESC-Norte, June 1989              *
  32.  *    MODIFIED BY: Antonio Costa, INESC-Norte, July 1992              *
  33.  **********************************************************************/
  34.  
  35. /***** Write picture *****/
  36. void
  37. init_picture()
  38. {
  39.   switch (output_format)
  40.   {
  41.   case 0:    /* PIC */
  42.     /* Screen Dimensions */
  43.     WRITE_CHAR(picture, (unsigned char) (screen_size_x MOD 256));
  44.     WRITE_CHAR(picture, (unsigned char) (screen_size_x DIV 256));
  45.     WRITE_CHAR(picture, (unsigned char) (screen_size_y MOD 256));
  46.     WRITE_CHAR(picture, (unsigned char) (screen_size_y DIV 256));
  47.     if (IO_status != IO_OK)
  48.       runtime_abort("unable to write PICTURE");
  49.     if (raw_mode == 1)
  50.     {
  51.       WRITE_CHAR(raw_picture, (unsigned char) (screen_size_x MOD 256));
  52.       WRITE_CHAR(raw_picture, (unsigned char) (screen_size_x DIV 256));
  53.       WRITE_CHAR(raw_picture, (unsigned char) (screen_size_y MOD 256));
  54.       WRITE_CHAR(raw_picture, (unsigned char) (screen_size_y DIV 256));
  55.       if (IO_status != IO_OK)
  56.         runtime_abort("unable to write RAW PICTURE");
  57.     }
  58.     break;
  59.   case 1:    /* PPM */
  60.     WRITE(picture, "P6\n");
  61.     WRITE(picture, "%d\n", screen_size_x);
  62.     WRITE(picture, "%d\n", screen_size_y);
  63.     WRITE(picture, "255\n");
  64.     if (IO_status != IO_OK)
  65.       runtime_abort("unable to write PICTURE in PPM format");
  66.     if (raw_mode == 1)
  67.     {
  68.       WRITE(raw_picture, "P6\n");
  69.       WRITE(raw_picture, "%d\n", screen_size_x);
  70.       WRITE(raw_picture, "%d\n", screen_size_y);
  71.       WRITE(raw_picture, "255\n");
  72.       if (IO_status != IO_OK)
  73.         runtime_abort("unable to write RAW PICTURE in PPM format");
  74.     }
  75.     break;
  76.   }
  77.   if (background_mode == 1)
  78.   {
  79.     WRITE_CHAR(background, (unsigned char) (screen_size_x MOD 256));
  80.     WRITE_CHAR(background, (unsigned char) (screen_size_x DIV 256));
  81.     WRITE_CHAR(background, (unsigned char) (screen_size_y MOD 256));
  82.     WRITE_CHAR(background, (unsigned char) (screen_size_y DIV 256));
  83.     if (IO_status != IO_OK)
  84.       runtime_abort("unable to write BACKGROUND MASK");
  85.   }
  86. }
  87. #define INDEX(v)\
  88. (ROUND(MAX(0.0, MIN((real) INDEX_MAX, (v) * (real) SUCC(INDEX_MAX)))))
  89.  
  90. void
  91. line_picture()
  92. {
  93.   REG int         i;
  94.  
  95.   for (i = 1; i <= screen_size_x; POSINC(i))
  96.   {
  97.     WRITE_CHAR(picture, (unsigned char) INDEX(true_color[i].r));
  98.     if (IO_status != IO_OK)
  99.       runtime_abort("unable to write PICTURE");
  100.     WRITE_CHAR(picture, (unsigned char) INDEX(true_color[i].g));
  101.     if (IO_status != IO_OK)
  102.       runtime_abort("unable to write PICTURE");
  103.     WRITE_CHAR(picture, (unsigned char) INDEX(true_color[i].b));
  104.     if (IO_status != IO_OK)
  105.       runtime_abort("unable to write PICTURE");
  106.     if (background_mode == 1)
  107.     {
  108.       WRITE_CHAR(background, (unsigned char) INDEX(back_mask[i]));
  109.       if (IO_status != IO_OK)
  110.         runtime_abort("unable to write BACKGROUND MASK");
  111.     }
  112.     if (raw_mode == 1)
  113.     {
  114.       WRITE_CHAR(raw_picture, (unsigned char) INDEX(new_line[i].color.r));
  115.       if (IO_status != IO_OK)
  116.         runtime_abort("unable to write RAW PICTURE");
  117.       WRITE_CHAR(raw_picture, (unsigned char) INDEX(new_line[i].color.g));
  118.       if (IO_status != IO_OK)
  119.         runtime_abort("unable to write RAW PICTURE");
  120.       WRITE_CHAR(raw_picture, (unsigned char) INDEX(new_line[i].color.b));
  121.       if (IO_status != IO_OK)
  122.         runtime_abort("unable to write RAW PICTURE");
  123.     }
  124.   }
  125.   FLUSH(picture);
  126.   if (background_mode == 1)
  127.     FLUSH(background);
  128.   if (raw_mode == 1)
  129.     FLUSH(raw_picture);
  130. }
  131.